﻿@model IEnumerable<CNRegex.Entity.RegexTutorialCatalog>

@{
    Layout = "~/Views/Shared/_LayoutBack.cshtml";
}
<script src="@Url.Content("~/Scripts/kindeditor/kindeditor-min.js")" type="text/javascript"></script>
<script type="text/javascript">
	var dialog;
	var dialogContent;
	function showCreate() {
		dialog = $("#dialog").dialog();
		$("input[name='Name']").val("");
		$("input[name='OrderIndex']").val("");
		$("input[name='IsLeaf']").val("");
		$("input[name='ID']").val("");
		$("textarea[name='Description']").val("");
		
	}

	function closeDialog() {
		$("#dialog").dialog("close");
	}
	function save() {
		var name = $("input[name='Name']").val();
		var orderIndex = $("input[name='OrderIndex']").val();
		var isLeaf = $("input[name='IsLeaf']").attr('checked');
		var level = $("input[name='Level']").val();
		var parentID = $("input[name='ParentID']").val();
		var id = $("input[name='ID']").val();
		var tutorialID = $("input[name='TutorialID']").val();
		var description = $("textarea[name='Description']").val()
		$.ajax({
			type: "POST",
			url: "/AdminRegexTutorialCatalog/Save",
			data: "name=" + name + "&orderIndex=" + orderIndex + "&isLeaf=" + isLeaf + (id == "" ? "" : "&id=" + id + "") + "&parentId=" + parentID + "&level=" + level + "&tutorialID="+tutorialID+"&description="+description,
			success: function (msg) {
				window.location = window.location;
			}
		});
	}

	function deleteItem(id) {
		if (!confirm("确定要删除?"))
			return;
		$.ajax({
			type: "POST",
			url: "/AdminRegexTutorialCatalog/Delete",
			data: "id=" + id,
			success: function (msg) {
				window.location = window.location;
			}
		});
	}

	function edit(id, name, orderIndex, isLeaf, description) {
		$("input[name='Name']").val(name);
		$("input[name='OrderIndex']").val(orderIndex);
		$("input[name='IsLeaf']").attr("checked",isLeaf=="False"?"":"checked");
		$("input[name='ID']").val(id);
		$("textarea[name='Description']").val(description);
		$("#dialog").dialog({ "width": "850" });
		KE.html("description", "")
	}

	$(document).ready(function () {
		registerKindeditor("description");
	});
	

</script>

<div class="stateBar">
	<img src="/images/dot.gif" alt="position" />
	您现在的位置 → <span class="bfont">@ViewBag.Tutorial.Name</span> → （@ViewBag.Level 级） 目录管理
</div>
<div class="toolBar">
	<span style="float: right; margin-right: 5px;">
		<a href="javascript:showCreate();"
		style="text-decoration: none;">
			<img src="/images/add.gif" alt="add" />
			<span style="position: relative; top: -3px;">新增</span> 
		</a>
	</span>
</div>
<table class="box-table-a">
	<colgroup>
		<col width="15%" />
		<col />
		<col />
	</colgroup>
	<tr>
		<th scope="col">
		</th>
		<th scope="col">
			目录名称
		</th>
		<th scope="col">
			描述
		</th>
		<th scope="col">
			排序
		</th>
		<th scope="col">
			级别
		</th>
		<th scope="col">
			是否叶子节点
		</th>

	</tr>
	@foreach (var item in Model)
 {
		<tr>
			<td align="center">
				<a href="javascript:edit('@item.ID','@item.Name','@item.OrderIndex','@item.IsLeaf','@item.Description')">编辑</a> |
				<a href="javascript:deleteItem('@item.ID')">删除</a>
				@if (!@item.IsLeaf.Value)
	{
		<a href="/AdminRegexTutorialCatalog/Index/?id=@ViewBag.Tutorial.ID&level=@(ViewBag.Level + 1)&parentID=@item.ID">进入子目录</a>
	}
	else
	{
		<a href="/AdminRegexTutorialCatalog/CatalogContent/@item.ID">叶子内容</a>
	}
				
			</td>
			<td>
				@item.Name
			</td>
			<td>
				@item.Description
			</td>
			<td>
				@item.OrderIndex
			</td>
			<td>
				@item.Level
			</td>
			<td>
				@item.IsLeaf
			</td>
		</tr>
 }
</table>

<div id="dialog" title="创建目录" style="display: none;">
	<p>
		<span>名称:</span>
		<input name="Name" />
	</p>
	<p>
		<span>描述:</span>
		<textarea id="description" name="Description" rows="3" cols="20"></textarea>
	</p>
	<p>
		<span>排序:</span>
		<input name="OrderIndex" />
	</p>
	<p>
		<span>叶子节点:</span>
		<input type="checkbox" name="IsLeaf" />
	</p>
	<div style="text-align: center; margin-top: 4px;">
		<input type="button" value="确定" onclick="save();" />
		<input type="button" value="取消" onclick="closeDialog();" />
	</div>
	<input type="hidden" name="Level" value="@ViewBag.Level" />
	<input type="hidden" name="TutorialID" value="@ViewBag.Tutorial.ID" />
	<input type="hidden" name="ParentID" value="@ViewBag.ParentID" />
	<input type="hidden" name="ID" />
</div>


